<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <script src="../vue.js"></script>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }

    html, body {
      height: 100%;
    }

    #root {
      height: 100%;
      display: flex;
      flex-direction: column;
    }

    main {
      flex: 1;
    }

    ul,li {
      list-style: none;
    }

    ul {
      height: 44px;
      background-color: #eee;
      display: flex;
    }

    li {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    li.active {
      background-color: aliceblue;
    }
  </style>
</head>
<body>
  <div id="root">
    <main>
      <component :is="componentId"></component>
    </main>
    <ul>
      <li :class="{active: tab.component === componentId}" v-for="tab in tabs" :key="tab.id" @click="handleClick(tab.component)">
        {{tab.title}}
      </li>
    </ul>
  </div>
  <script type="module">
    Vue.config.productionTip = false

    const comp1 = {
      template: `
        <div>component 1</div>
      `,
      mounted() {
        
      },
    }
    const comp2 = {
      template: `
        <div>component 2</div>
      `
    }
    const comp3 = {
      template: `
        <div>component 3</div>
      `
    }

    var vm = new Vue({
      el: '#root',
      data: {
        tabs: [
          {
            id: '001',
            title: '首页',
            component: 'comp1'
          },
          {
            id: '002',
            title: '搜索',
            component: 'comp2'
          },
          {
            id: '003',
            title: '我的',
            component: 'comp3'
          }
        ],

        componentId: 'comp1'
      },

      components: {
        comp1,
        comp2,
        comp3
      },

      methods: {
        handleClick(comp) {
          this.componentId = comp
        }
      },
    })
  </script>
</body>
</html>